<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col
            :md="8"
            :sm="24">
            <a-form-item label="文件名">
              <a-input
                v-model="queryParam.keyword"
                placeholder="请输入文件名" />
            </a-form-item>
          </a-col>
          <a-col
            :md="4"
            :sm="12">
            <a-form-item label="文件类别">
              <a-select v-model="queryParam.fileType">
                <a-select-option
                  value=""
                  key="type_0">全部类型</a-select-option>
                <a-select-option
                  v-for="(item, key) in typeList"
                  :key="'type_' + key"
                  :value="key">{{ item }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col
            :md="8"
            :sm="24">
            <a-form-item label="日志时间">
              <a-range-picker
                :showTime="{ format: 'HH:mm:ss' }"
                format="YYYY-MM-DD HH:mm:ss"
                :placeholder="['开始时间', '结束时间']"
                v-model="queryParam.timeArea"
                @change="onQueryParamChange" />
            </a-form-item>
          </a-col>
          <a-col
            :md="4"
            :sm="12">
            <span
              class="table-page-search-submitButtons"
              :style="{ float: 'right', overflow: 'hidden' } || {} ">
              <a-button
                type="primary"
                @click="$refs.table.refresh(true)">查询</a-button>
              <a-button
                style="margin-left: 8px"
                @click="() => queryParam = {}">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <s-table
      ref="table"
      size="default"
      rowKey="file_id"
      :columns="columns"
      :data="loadData"
      showPagination="auto">
      <span
        slot="view_url"
        slot-scope="text, record">
        <template>
          <a-button
            size="small"
            icon="search"
            type="primary"
            v-if="$auth('admin.sys-file.check')"
            @click="$refs.checkModal.open(record)">查看</a-button>
        </template>
      </span>
    </s-table>
    <check-modal
      ref="checkModal"
      @ok="$refs.table.refresh()" />
  </a-card>
</template>

<script>
import moment from 'moment'
import { STable } from '@/components'
import checkModal from './modules/SysFileCheckForm'
import { loadList } from '@/api/system/sysfile'

export default {
  name: 'SysFile',
  components: {
    STable,
    checkModal
  },
  data () {
    return {
      mdl: {},
      // 查询参数
      queryParam: { fileType: '' },
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: 'file_id'
        },
        {
          title: '文件类型',
          dataIndex: 'file_type_str'
        },
        {
          title: '文件路径',
          dataIndex: 'file_path'
        },
        {
          title: '原始文件名',
          dataIndex: 'origin_name'
        },
        {
          title: '新文件名',
          dataIndex: 'new_name'
        },
        {
          title: '文件大小',
          dataIndex: 'file_size'
        },
        {
          title: '文件后缀名',
          dataIndex: 'file_ext'
        },
        {
          title: '添加时间',
          dataIndex: 'created_at',
          customRender: (text, row, index) => {
              return moment(text).format('YYYY-MM-DD HH:mm:ss')
          }
        },
        {
          title: '预览',
          dataIndex: 'view_url',
          width: '150px',
          scopedSlots: { customRender: 'view_url' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return loadList(Object.assign(parameter, this.queryParam))
          .then(res => {
            this.typeList = res.data.typeList
            return {
            pageNo: res?.data?.pageNo || 1,
            totalCount: res?.data?.total || 0,
            data: res?.data?.list || []
            }
          })
      },
      typeList: []
    }
  },
  created () {
  },
  methods: {
    onQueryParamChange (value, dateString) {
      // console.log('Selected Time: ', value);
      // console.log('Formatted Selected Time: ', dateString);
      this.queryParam.timeArea = dateString
    },
    handleCheck (record) {

    }
  }
}
</script>
